/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TAREA_lab5.java
 *
 * Created on 26-jun-2012, 0:23:08
 */
package Almacenamiento;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultCellEditor;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.SwingUtilities;

import javax.swing.table.DefaultTableModel;


public class TAREA_lab5 extends JFrame{

    private static final long serialVersionUID = 1L;

    protected JTable table = null;

  private JScrollPane scrollPane=null;

    private class TABLE_MODEL extends DefaultTableModel{

        public static final String INITIAL_VALUE = "DATO 1";

        private static final long serialVersionUID = 1L;

        public TABLE_MODEL(){

            this.addColumn(COLUMN1);

            this.addColumn(COLUMN2);

            this.addColumn(COLUMN3);

        }

        public static final String COLUMN1="NOmbre";

        public static final String COLUMN2="B";

       public static final String COLUMN3="Tipos";

        public void addData(String a,String b){

            final Object rowData[]={a,b,INITIAL_VALUE};

          this.addRow(rowData);

        }

  }

    private TABLE_MODEL model=new TABLE_MODEL();

    public static final String[] DATA = { "Dato 1", "Dato 2", "Dato 3", "Dato 4" };

    public TAREA_lab5(){

       
        
        JComboBox comboBox = new JComboBox(DATA);

        DefaultCellEditor defaultCellEditor=new DefaultCellEditor(comboBox);
        //table.getColumnModel().getColumn(2).setCellEditor(defaultCellEditor);

        table=new JTable(model);

        table.getColumnModel().getColumn(2).setCellEditor(defaultCellEditor);
        table.setLocation(100, 100);

       scrollPane=new JScrollPane(table);

        this.getContentPane().add(scrollPane);

        this.setSize(500,500);
        table.setSize(300, 300);

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   

        addData();

    }

    public void addData(){

        model.addData("valor 1", "valor 2");

        model.addData("valor 3", "valor 4");

        model.addData("valor 5", "valor 6");

    }

/**
 *
 * @author User
 */


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(jButton1))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(52, 52, 52)
                .addComponent(jButton1)
                .addGap(28, 28, 28)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(189, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
/*1) Representar el esquema de la relación 
    Esquema_Cliente = (id_cliente, nombre_cliente, direccion_cliente, telefono_cliente), donde:
    id_cliente tiene dominio de valores enteros,
    nombre_cliente tiene dominio de valores de cadena de caracteres,
    direccion_cliente tiene dominio de valores de cadena de caracteres,
    telefono_cliente tiene dominio de valores entero largo.
    Seguidamente, muestre el esquema creado en pantalla. Modifique el esquema de tal manera 
     * que se añada un nuevo atributo denominado tipo_cliente con dominio de valores de tipo 
     * carácter luego muéstrelo en pantalla. Finalmente modifique nuevamente el esquema para 
     * eliminar el atributo telefono_cliente y luego muestre el esquema resultante.*/
    //ejecutar sentencia 
    //verificar la correctitud  -> falñta implementar asumir k la sintaxis es correcta y k se está creando un tabla

    Relacion Cliente = new Relacion();
    List<Atributo> at = new ArrayList<Atributo>();
    at.add(new Atributo("id_Cliente", Integer.class));
    at.add(new Atributo("nombre_cliente", String.class));
    at.add(new Atributo("direccion_cliente", String.class));
    at.add(new Atributo("telefono_Cliente", Long.class));

    Cliente.setAtributos(at);
    jTextArea1.setText("1." + Cliente.toString());
    at.add(new Atributo("tipo_cliente", Character.class));
    Cliente.setAtributos(at);
    jTextArea1.setText(jTextArea1.getText() + " \n 2." + Cliente.toString());
    Atributo att = new Atributo("telefono_Cliente", Long.class);
    at.remove(att);
    Cliente.setAtributos(at);
    jTextArea1.setText(jTextArea1.getText() + " \n 3." + Cliente.toString());
   






}//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TAREA_lab5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TAREA_lab5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TAREA_lab5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TAREA_lab5.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new TAREA_lab5().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables
}
